package org.ruanjj.maxprofit2;

public class Solution {
    public int maxProfit(int[] prices) {
        int n = prices.length;
        int maxProfitVal = 0;
        int min = prices[0];

        for(int i = 0; i < n; i++) {
            if (prices[i] > min) {
                maxProfitVal = maxProfitVal + prices[i] - min;
            }
            min = prices[i];
        }

        return maxProfitVal;
    }
}
